import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { OutRequestStateService } from 'src/app/service/out-request-state.service';
import { OutRequest } from 'src/app/domain/out-request';
import { AuthService } from '../../../service/auth.service';
import { ManagerService } from './../../../service/manager.service';
import { User } from 'src/app/domain/user';

/*

@Author:赵明洋

@Date: 2018-12-12

@员工外出查询功能实现

@Last Modified time: 2018-12-16
*/

@Component({
  selector: 'app-out-request-state',
  templateUrl: './out-request-state.component.html',
  styleUrls: ['./out-request-state.component.css']
})
export class OutRequestStateComponent implements OnInit {
  private manager: User;
  sid =AuthService.getUserId();
  private suggestion = null;

 OutRequests: OutRequest[];

 
  constructor(public router:Router,  private outrequeststate :OutRequestStateService,private managerService: ManagerService ) { 

    this.manager = {
      id: null,
      user_name: null,
      name: null,
      age: null,
      sex: null,
      department: null, //部门
      position: null, //职务
      annual_leave_length: null, //年假上限
      remain_annual_leave: null, //剩余年假
    };
  }

  create()
  {
    this.router.navigateByUrl('/staff/outrequeststate/0');
  }
  
  update(outrequest:OutRequest)
  {
    this.router.navigateByUrl('/staff/outrequeststate/'+ outrequest.id)
  }
  
  getOutRequests(): void {
    // this.OutRequests = this.outrequeststate.getOutRequests();       //调用服务的方法获取请求信息
    this.outrequeststate.getOutRequests()
    .subscribe(OutRequests => this.OutRequests = OutRequests);
   } 
     
   delete(outrequest:OutRequest)
   {   
      console.log(outrequest)
      this.outrequeststate.deleteoutRequest(outrequest)
      .subscribe(data => console.log(data));
      this.ngOnInit()
   }




  selectType(type:number)
  {
     if(type ==0)
     {
       return "病假";
     }
     if(type ==1)
     {
       return "婚假";
     }
     if(type ==2)
     {
       return "事假";
     }
  }

  selectState(state:number)
  {
    if(state ==0)
    {
      return "未通过";
    }

    if(state ==1)
    {
      return "已通过";
    }
    if(state ==2)
    {
      return "等待部门经理审批";
    }

    if(state ==3)
    {
      return "等待副总经理审批";
    }
    if(state ==4)
    {
      return "等待总经理审批";
    }
  }

 
  ngOnInit() {
    this.getUser();      //调用注入服务的函数
  }

  getUser(){
    var id = AuthService.getUserId();
    if(id == 0){
      alert("请先登录");
    }
    else{
      this.managerService.getUser(id)
      .subscribe(manager => {this.manager = manager[0];console.log("dsdsad");
      this.getOutRequests();  
    
    });
    }
  }
  lookSuggestion(suggestion: string){
    this.suggestion = suggestion;
  }

  backSuggestion(){
    this.suggestion = null;
  }
}
